//重写extjs合计行
Ext.grid.feature.Summary.override({
	generateSummaryData : function() {
		if (this.view.store.totalCount == 0) {
			var sumMap = {};
			var columns = this.view.grid.columns;
			for ( var i in columns) {
				if (columns[i].summaryType == "sum") {
					var dataindex = columns[i].dataIndex;
					sumMap[dataindex] = '';
				}
			}
			this.view.store.getProxy().reader.rawData[this.remoteRoot] = sumMap;
		}
		return this.view.store.getProxy().reader.rawData[this.remoteRoot];
	}
});
var classNameArray=[]
Ext.onReady(function() {
	$('img.img-collapsible').click(toggleTopHidden); 
	Ext.Ajax.request({
		method : 'POST',
		url : "/sys-report/getReportTablesStyle",
		params : {
			tables_id : tables_id
		},
		async : false,
		success : function(response, options) {
			var respText = Ext.util.JSON.decode(response.responseText);
			var cssUrlArr=[];
			classNameArray=[]
			if(respText.tablesList&&respText.tablesList.length>0){
				respText.tablesList.forEach(function (item,index) {
					var arr=[]
					if(item.CSS_URL){
						arr=item.CSS_URL.split("?")
					}
					if(arr&&arr.length>0){
						item.CSS_URL=arr[0];
						item.CLASSNAME=arr[1]?arr[1].split("=")[1]:"";
					}
					let filterArr=cssUrlArr.filter(function (data) {
						return item.CSS_URL&&data.CSS_URL==item.CSS_URL
					})
					if(filterArr&&filterArr.length==0&&item.CSS_URL){
						cssUrlArr.push(item)
					}
					classNameArray.push(item)
				})
			}
			if(cssUrlArr&&cssUrlArr.length>0){
				cssUrlArr.forEach(function (item,index) {
					var link = document.createElement("link");
					link.type = "text/css";
					link.rel = "stylesheet";
					link.href = item.CSS_URL;
					document.getElementsByTagName("head")[0].appendChild(link);
				})
			}else{
				var cssUrl = respText.cssUrl;
				if (isNull(cssUrl)) {
					// 设置css默认样式
					cssUrl = "/report/page/plat/query/template/css/report.css";
				}
				var link = document.createElement("link");
				link.type = "text/css";
				link.rel = "stylesheet";
				link.href = cssUrl;
				document.getElementsByTagName("head")[0].appendChild(link);
			}
			var jsUrl = respText.jsUrl;
			
			if (isNull(jsUrl)) {
				// 设置js默认样式
				jsUrl = "/report/page/plat/query/template/js/report.js";
			}
			$.ajaxSetup({
				cache : true
			});
			$.getScript(jsUrl, function() {
				new Ext.panel.Panel({
					renderTo : Ext.getBody(),
					layout : 'fit',
					height : '100%',
					width : '100%',
					border : false,
					items : [ initReportQueryTablesPanel(tables_id, q_condition) ]
				});
			});
		},
		failure : function(response, options) {
			Ext.MessageBox.minWidth = 120;
			Ext.Msg.alert('提示', '获取报表配置信息失败！');
		}
	});
});
